package com.geek.novel.entity

import com.geek.novel.utils.FormatUtil
import com.geek.novel.utils.GsonUtil
import com.geek.novel.vo.CrawlConfigVo
import io.realm.RealmObject
import io.realm.annotations.PrimaryKey
import io.realm.annotations.RealmClass


/**
 * 爬虫源
 * @Author Hydra
 * @Date 2022/7/12 17:09
 */
@RealmClass
open class CrawlerSource : RealmObject() {
	
	/**
     * id
     */
	@PrimaryKey
    open var id: Long? = null
	
	open var name: String? = null
	
	open var active: Boolean? = null
	
	open var baseUrl: String? = null
	
	/**全部书本的目录 */
	open var bookPageUrl: String? = null
	
	/**全部章节的目录 */
	open var indexPageUrl: String? = null
	
	/**当前爬取的章节目录(下次从这里开始爬起) */
	open var curIndexPageUrl: String? = null
	
	/**同章下一页的目标元素的id */
	open var nextPageElemId: String? = null
	
	/**
	 * 爬虫配置
	 */
	open var config: String? = null
	
	open fun getCrawlerConfig(): CrawlConfigVo {
		val configJson = FormatUtil.isNullToString(config, "{}")
		return GsonUtil.fromJson(configJson, CrawlConfigVo::class.java)
	}

}